package reviewAlgorithms.ListNode;

public class OddEvenList {
    public static void main(String[] args) {

    }
    public ListNode oddEvenList(ListNode head) {
        if (head == null || head.next == null){
            return head;
        }
        ListNode before = head;
        ListNode left = head.next;
        ListNode right = head.next;
        while (right != null && right.next != null){
            ListNode next = right.next;
            ListNode temp = next.next;
            before.next = next;
            next.next = left;
            right.next = temp;
            right = temp;
            before = next;
        }
        return head;
    }
}
